<template>
	<view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			this.handleLogin()
		},
		computed: {

		},
		methods: {
			...mapMutations(['setPersonType']),
			handleLogin(e) {
				let that = this
				uni.showLoading({
					title: '登陆中'
				})
				const appId = uni.getAccountInfoSync().miniProgram.appId;
				let groupId
				if(appId == 'wx136dcc982e29f87b' || appId == 'wx21a1fa1c495a9515' ) {
					groupId = 36
				}else if(appId == 'wx21a1fa1c495a9515') {
					groupId = 1
				}else {
					groupId = 36
				}
				uni.setStorageSync('groupId', groupId)
				
				uni.login({
					provider: 'weixin',
					success: res => {
						console.log(res.code)
						// return
						if (res.code) {
							//发起网络请求
							// this.code = res.code
							this.$http2.post('auth/wx/code2login', {
								code: res.code,
								authType: 3,
								groupId: uni.getStorageSync('groupId')
							}).then(res => {
								console.log(res)
								if (res.code === 50004) {
									uni.setStorageSync('authkey', res.data.authkey)
									uni.navigateTo({
										url: '/ticketSystem/phoneVerify/phoneVerify'
									})
									// uni.showModal({
									// 	title: '提示',
									// 	content: '用户不存在,请进行账号验证',
									// 	success: function(res) {
									// 		if (res.confirm) {
									// 			console.log('123')
									// 			uni.navigateTo({
									// 				url: '/pages/phoneVerify/phoneVerify'
									// 			})
									// 		} else if (res.cancel) {
									// 			uni.navigateBack({
									// 			    delta: 1
									// 			});
									// 		}
									// 	}
									// })
								} else if (res.code === 50010) {
									uni.navigateTo({
										url: '/ticketSystem/phoneVerify/phoneVerify'
									})
								} else if (res.code === 10000) {
									uni.showToast({
										title: '登录成功'
									})
									// this.getUserInfo()
									uni.setStorageSync('login', true)
									
									setTimeout(() => {
										uni.switchTab({
											url: '/pages/index/index'
										})
									}, 1000)
								}
							})
						} else {
							console.log('登录失败！' + res.errMsg)
						}
					}
				})
			}
			// getUserInfo() {
			// 	this.$http2.post('ticketSystem/operator/info', {
			// 		id: 0
			// 	}).then(res => {
			// 		console.log(res)
			// 		if (res.code === 10000) {
			// 			this.setPersonType(res.data.人员类型)
			// 			uni.setStorageSync('userInfo', res.data)
			// 			uni.setStorageSync('id', res.data.id)
			// 			uni.setStorageSync('unitId', res.data.所属单位)
			// 			uni.setStorageSync('projectList', res.data.负责项目不可修改)
			// 		}
			// 	})
			// },
		}
	}
</script>

<style>

</style>
